/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

#include "../Types.h"

#include "buffer.h"

void buffer_data_init( buffer_data * brd, char * data, int size )
{
	brd->data = data;
	brd->size= size;
	brd->pos=0;
}

int bufferReader( type_input_stream * in, void * data, char * buffer, int size )
{
	buffer_data * brd = (buffer_data *) data;
	int toRead = ( brd->pos + size > brd->size )? brd->size - brd->pos: size;
	
	memcpy( buffer, &(brd->data[ brd->pos ]), toRead );
	brd->pos = brd->pos+toRead;
	return toRead;
}

int bufferWriter( type_output_stream * out, void * data, char * buffer, int size )
{
	buffer_data * brd = (buffer_data *) data;
	int toWrite = (( brd->pos + size ) > brd->size) ? brd->size - brd->pos: size;
	
	memcpy( &(brd->data[ brd->pos ]), buffer, toWrite );
	brd->pos = brd->pos+toWrite;
	return toWrite;
}
